from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

from cart.models import CartModel


class CartSer(ModelSerializer):
    coulist = SerializerMethodField(allow_null=True)
    def get_coulist(self,obj):
        return {"name":obj.goods.name,'price':obj.goods.price,'cover':obj.goods.cover,"level":obj.goods.level}
    class Meta:
        model = CartModel
        fields = "__all__"
